﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Renk = System.Drawing.Color;
using System.Drawing;

namespace SemiCASE.UserControls
{
    public partial class GenelTextBox : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
            }

            GenelTextBox gtxBx = (GenelTextBox)sender;
            MaskelemeTipiniAyarla(gtxBx.uciMaskelemeTipi);
            YazimSekliniAyarla(gtxBx.uciYazimSekli);
            EtiketOzellikleriniAyarla();
            KontrolZorunlulukAyari(gtxBx.uciZorunlu);

            if (GenelMetinKutusu.Text == string.Empty && HiddenFieldText.Value != string.Empty) GenelMetinKutusu.Text = HiddenFieldText.Value;
        }

        #region "TextBox EVENTS"

        protected virtual void OnTextChanged(EventArgs e)
        {

            EventHandler handler = (EventHandler)base.Events[EventChanged];
            if (handler != null)
            {
                handler(this, e);
            }
        }

        private static readonly object EventChanged;

        public event EventHandler TextChanged
        {
            add
            {
                this.GenelMetinKutusu.TextChanged += value;
                base.Events.AddHandler(EventChanged, value);
            }
            remove
            {
                this.GenelMetinKutusu.TextChanged -= value;
            }
        }

        public static explicit operator TextBox(GenelTextBox arg)
        {
            return arg.GenelMetinKutusu;
        }

        #endregion

        #region "TextBox PROPERTIES"

        public string Text
        {
            get { return GetEdilenMetinFormatiniAyarla(); }
            set { SetEdilenMetinFormatiniAyarla(value); }
        }
        public Color ForeColor
        {
            get { return GenelMetinKutusu.ForeColor; }
            set { GenelMetinKutusu.ForeColor = value; }
        }
        public Color BackColor
        {
            get { return GenelMetinKutusu.BackColor; }
            set { GenelMetinKutusu.BackColor = value; }
        }
        public Color BorderColor
        {
            get { return GenelMetinKutusu.BorderColor; }
            set { GenelMetinKutusu.BorderColor = value; }
        }
        public BorderStyle BorderStyle
        {
            get { return GenelMetinKutusu.BorderStyle; }
            set { GenelMetinKutusu.BorderStyle = value; }
        }
        public Unit BorderWidth
        {
            get { return GenelMetinKutusu.BorderWidth; }
            set { GenelMetinKutusu.BorderWidth = value; }
        }
        public Unit Width
        {
            get { return GenelMetinKutusu.Width; }
            set { GenelMetinKutusu.Width = value; }
        }
        public Unit Height
        {
            get { return GenelMetinKutusu.Height; }
            set { GenelMetinKutusu.Height = value; }
        }
        public int MaxLength
        {
            get { return GenelMetinKutusu.MaxLength; }
            set { GenelMetinKutusu.MaxLength = value; HiddenFieldMaxLength.Value = value.ToString(); }
        }
        public bool ReadOnly
        {
            get { return GenelMetinKutusu.ReadOnly; }
            set { GenelMetinKutusu.ReadOnly = value; }
        }
        public bool Enabled
        {
            get { return GenelMetinKutusu.Enabled; }
            set { GenelMetinKutusu.Enabled = value; }
        }
        public string ValidationGroup
        {
            get { return GenelMetinKutusu.ValidationGroup; }
            set { GenelMetinKutusu.ValidationGroup = value; }
        }
        public override bool Visible
        {
            get { return ViewState["uciVisible"] == null ? true : (bool)ViewState["uciVisible"]; }
            set { ViewState["uciVisible"] = value; KontrolVisibleAyari(value); }
        }
        private void KontrolVisibleAyari(bool pVisible)
        {
            if (pVisible)
            {
                GenelMetinKutusu.Style.Add("display", "block");
            }
            else
            {
                GenelMetinKutusu.Style.Add("display", "none");
            }
        }
        public TextBoxMode TextMode
        {
            get { return GenelMetinKutusu.TextMode; }
            set { GenelMetinKutusu.TextMode = value; if (value==TextBoxMode.MultiLine) HiddenFieldMultiLine.Value="1";else HiddenFieldMultiLine.Value="0";}
        }
        public string ToolTip
        {
            get { return GenelMetinKutusu.ToolTip; }
            set { GenelMetinKutusu.ToolTip = value; }
        }
        public AutoCompleteType AutoCompleteType
        {
            get { return GenelMetinKutusu.AutoCompleteType; }
            set { GenelMetinKutusu.AutoCompleteType = value; }
        }
        public bool AutoPostBack
        {
            get { return GenelMetinKutusu.AutoPostBack; }
            set { GenelMetinKutusu.AutoPostBack = value; HiddenFieldAutoPostback.Value = Convert.ToByte(value).ToString(); }
        }
        public bool CausesValidation
        {
            get { return GenelMetinKutusu.CausesValidation; }
            set { GenelMetinKutusu.CausesValidation = value; }
        }
        public override string ClientID
        {
            get { return GenelMetinKutusu.ClientID; }
        }
        public int Columns
        {
            get { return GenelMetinKutusu.Columns; }
            set { GenelMetinKutusu.Columns = value; }
        }
        public int Rows
        {
            get { return GenelMetinKutusu.Rows; }
            set { GenelMetinKutusu.Rows = value; }
        }
        public short TabIndex
        {
            get { return GenelMetinKutusu.TabIndex; }
            set { GenelMetinKutusu.TabIndex = value; }
        }
        public bool FontBold
        {
            get { return GenelMetinKutusu.Font.Bold; }
            set { GenelMetinKutusu.Font.Bold = value; }
        }
        public bool FontItalic
        {
            get { return GenelMetinKutusu.Font.Italic; }
            set { GenelMetinKutusu.Font.Bold = value; }
        }
        public FontUnit FontSize
        {
            get { return GenelMetinKutusu.Font.Size; }
            set { GenelMetinKutusu.Font.Size = value; }
        }
        public string FontName
        {
            get { return GenelMetinKutusu.Font.Name; }
            set { GenelMetinKutusu.Font.Name = value; }
        }
        public string CssClass
        {
            get { return GenelMetinKutusu.CssClass; }
            set { GenelMetinKutusu.CssClass = value; }
        }

        #endregion

        #region "TextBox METHODS"

        public void DataBind()
        {
            GenelMetinKutusu.DataBind();
        }

        public void Dispose()
        {
            GenelMetinKutusu.Dispose();
        }

        public void Focus()
        {
            GenelMetinKutusu.Focus();
        }

        public int GetHashCode()
        {
            return GenelMetinKutusu.GetHashCode();
        }

        public Type GetType()
        {
            return GenelMetinKutusu.GetType();
        }

        #endregion

        #region "Control PROPERTIES"

        public enum MaskelemeTipleri
        {
            Serbest = 0,
            SadeceRakam = 1,
            SadeceYazi = 2,
            Telefon = 3,
            OndalikliRakam = 4,
            Para = 5,
            YazismaKodu = 6,
            Eposta = 7,
            WebAdresi = 8,
            Sayi = 9,
            UlkeTelefonKodu = 10,
            KurumsalKod = 11,
            FonksiyonelKod = 12,
            FinansalKod = 13,
            ParaKurussuz = 14,
            ButceEkonomikKod = 15
        }
        public enum YazimSekli
        {
            Serbest,
            HepsiKucuk,
            HepsiBuyuk,
            BasharflerBuyuk
        }

        public bool uciZorunlu
        {
            get { return ViewState["uciZorunlu"] == null ? false : (bool)ViewState["uciZorunlu"]; }
            set { ViewState["uciZorunlu"] = value; KontrolZorunlulukAyari(value); }
        }
        public MaskelemeTipleri uciMaskelemeTipi
        {
            get { return ViewState["uciMaskelemeTipi"] == null ? MaskelemeTipleri.Serbest : (MaskelemeTipleri)ViewState["uciMaskelemeTipi"]; }
            set { ViewState["uciMaskelemeTipi"] = value; }
        }
        public YazimSekli uciYazimSekli
        {
            get { return ViewState["uciYazimSekli"] == null ? YazimSekli.Serbest : (YazimSekli)ViewState["uciYazimSekli"]; }
            set { ViewState["uciYazimSekli"] = value; }
        }
        public bool uciOrnekGoster
        {
            get { return ViewState["uciOrnekGoster"] == null ? false : (bool)ViewState["uciOrnekGoster"]; }
            set { ViewState["uciOrnekGoster"] = value; }
        }
        public string uciFocusBackColor
        {
            get { return ViewState["uciFocusBackColor"] == null ? "#f0f8ff" : (string)ViewState["uciFocusBackColor"]; }
            set { ViewState["uciFocusBackColor"] = value; HiddenFieldFocusBackColor.Value = value; }
        }
        public string uciFocusForeColor
        {
            get { return ViewState["uciFocusForeColor"] == null ? "#0080ff" : (string)ViewState["uciFocusForeColor"]; }
            set { ViewState["uciFocusForeColor"] = value; HiddenFieldFocusForeColor.Value = value; }
        }
        public string uciBlurBackColor
        {
            get { return ViewState["uciBlurBackColor"] == null ? "#ffffff" : (string)ViewState["uciBlurBackColor"]; }
            set { ViewState["uciBlurBackColor"] = value; HiddenFieldBlurBackColor.Value = value; }
        }
        public string uciBlurForeColor
        {
            get { return ViewState["uciBlurForeColor"] == null ? "#000000" : (string)ViewState["uciBlurForeColor"]; }
            set { ViewState["uciBlurForeColor"] = value; HiddenFieldBlurForeColor.Value = value; }
        }
        public string uciLabelText
        {
            get { return ViewState["uciLabelText"] == null ? string.Empty : (string)ViewState["uciLabelText"]; }
            set { ViewState["uciLabelText"] = value; }
        }
        public FontUnit uciLabelFontSize
        {
            get { return ViewState["uciLabelFontSize"] == null ? FontUnit.Small : (FontUnit)ViewState["uciLabelFontSize"]; }
            set { ViewState["uciLabelFontSize"] = value; }
        }
        public bool uciLabelFontBold
        {
            get { return ViewState["uciLabelFontBold"] == null ? false : (bool)ViewState["uciLabelFontBold"]; }
            set { ViewState["uciLabelFontBold"] = value; }
        }
        public bool uciLabelFontItalic
        {
            get { return ViewState["uciLabelFontItalic"] == null ? false : (bool)ViewState["uciLabelFontItalic"]; }
            set { ViewState["uciLabelFontItalic"] = value; }
        }
        public string uciLabelFontName
        {
            get { return ViewState["uciLabelFontName"] == null ? "Segoe UI" : (string)ViewState["uciLabelFontName"]; }
            set { ViewState["uciLabelFontName"] = value; }
        }
        public int uciLabelWidth
        {
            get { return ViewState["uciLabelWidth"] == null ? 0 : (int)ViewState["uciLabelWidth"]; }
            set { ViewState["uciLabelWidth"] = value; }
        }
        public double uciMinimumSayi
        {
            get { return ViewState["uciMinimumSayi"] == null ? 0 : (double)ViewState["uciMinimumSayi"]; }
            set { ViewState["uciMinimumSayi"] = value; }
        }
        public double uciMaksimumSayi
        {
            get { return ViewState["uciMaksimumSayi"] == null ? 0 : (double)ViewState["uciMaksimumSayi"]; }
            set { ViewState["uciMaksimumSayi"] = value; }
        }

        public enum TextAlign
        {
            center = 0,
            justify = 1,
            left = 2,
            right = 3,
            inherit = 4
        }
        public TextAlign uciTextAlign
        {
            get { return ViewState["uciTextAlign"] == null ? TextAlign.left : (TextAlign)ViewState["uciTextAlign"]; }
            set { ViewState["uciTextAlign"] = value; SetTextAligne(value); }
        }
        private void SetTextAligne(TextAlign value)
        {
            switch (value)
            {
                case TextAlign.center: GenelMetinKutusu.Style.Add("text-align", "center"); break;
                case TextAlign.inherit: GenelMetinKutusu.Style.Add("text-align", "inherit"); break;
                case TextAlign.justify: GenelMetinKutusu.Style.Add("text-align", "justify"); break;
                case TextAlign.left: GenelMetinKutusu.Style.Add("text-align", "left"); break;
                case TextAlign.right: GenelMetinKutusu.Style.Add("text-align", "right"); break;
            }
        }

        public TextAlign uciLabelTextAlign
        {
            get { return ViewState["uciLabelTextAlign"] == null ? TextAlign.left : (TextAlign)ViewState["uciLabelTextAlign"]; }
            set { ViewState["uciLabelTextAlign"] = value; SetLabelTextAlign(value); }
        }
        private void SetLabelTextAlign(TextAlign value)
        {
            switch (value)
            {
                case TextAlign.center: GenelEtiket.Style.Add("text-align", "center"); break;
                case TextAlign.inherit: GenelEtiket.Style.Add("text-align", "inherit"); break;
                case TextAlign.justify: GenelEtiket.Style.Add("text-align", "justify"); break;
                case TextAlign.left: GenelEtiket.Style.Add("text-align", "left"); break;
                case TextAlign.right: GenelEtiket.Style.Add("text-align", "right"); break;
            }
        }

        public int uciMinLength
        {
            get { return ViewState["uciMinLength"] == null ? 0 : (int)ViewState["uciMinLength"]; }
            set { ViewState["uciMinLength"] = value; HiddenFieldMinLength.Value = value.ToString(); }
        }

        public bool uciKarakterSayaciniGoster
        {
            get { return ViewState["uciKarakterSayaciniGoster"] == null ? true : (bool)ViewState["uciKarakterSayaciniGoster"]; }
            set { ViewState["uciKarakterSayaciniGoster"] = value; if (value) LabelKalanKarakterSayisi.Style.Add("display", "block"); else LabelKalanKarakterSayisi.Style.Add("display", "none"); }
        }

        public string uciMarginLeft
        {
            get { return ViewState["uciMarginLeft"] == null ? "0px" : (string)ViewState["uciMarginLeft"]; }
            set { ViewState["uciMarginLeft"] = value; GenelMetinKutusu.Style.Add("margin-left", value); }
        }

        #endregion

        private void EtiketOzellikleriniAyarla()
        {
            GenelEtiket.Text = uciLabelText;
            GenelEtiket.Font.Size = uciLabelFontSize;
            GenelEtiket.Font.Bold = uciLabelFontBold;
            GenelEtiket.Font.Italic = uciLabelFontItalic;
            GenelEtiket.Font.Name = uciLabelFontName;

            if (uciZorunlu) GenelEtiket.ForeColor = Color.Red; else GenelEtiket.ForeColor = Color.Black;
            if (!String.IsNullOrEmpty(GenelEtiket.Text) && uciLabelWidth > 0) GenelEtiket.Width = uciLabelWidth;
        }

        private void MaskelemeTipiniAyarla(MaskelemeTipleri pMaskelemeTipi)
        {
            string regExpression = string.Empty;
            string ornekFormat = string.Empty;
            LabelOrnek.Text = string.Empty;
            RegularExpressionValidatorGenelMetinKutusu.Visible = false;
            RangeValidatorGenelMetinKutusu.Visible = false;

            switch (pMaskelemeTipi)
            {
                case MaskelemeTipleri.Serbest:
                    HiddenFieldMaskelemeTipi.Value = "0";
                    break;
                case MaskelemeTipleri.SadeceRakam:
                    regExpression = @"(\d+)(\ )?";
                    HiddenFieldMaskelemeTipi.Value = "1";
                    OzelDogrulamaAyariYap(pMaskelemeTipi);
                    ornekFormat = "10";
                    break;
                case MaskelemeTipleri.SadeceYazi:
                    regExpression = @"(\D+)";
                    HiddenFieldMaskelemeTipi.Value = "2";
                    ornekFormat = "sadece yazı";
                    break;
                case MaskelemeTipleri.Telefon:
                    //regExpression = @"(\()(\d{3})(\))(\d{3}) (\d{2}) (\d{2})";
                    regExpression = @"(\()([1-9][0-9][0-9])(\))(\d{3}) (\d{2}) (\d{2})";
                    HiddenFieldMaskelemeTipi.Value = "3";
                    GenelMetinKutusu.MaxLength = 14;
                    ornekFormat = "(312)410 XX XX";
                    break;
                case MaskelemeTipleri.OndalikliRakam:
                    regExpression = @"(\d+)(,)(\d+)(\ )?";
                    HiddenFieldMaskelemeTipi.Value = "4";
                    ornekFormat = "10,05";
                    OzelDogrulamaAyariYap(pMaskelemeTipi);
                    break;
                case MaskelemeTipleri.Para:
                    HiddenFieldMaskelemeTipi.Value = "5";
                    ornekFormat = "1.520,50";
                    OzelDogrulamaAyariYap(pMaskelemeTipi);
                    break;
                case MaskelemeTipleri.YazismaKodu:
                    regExpression = @"(\D)(\.)(\d{2})(\.)(\d)(\.)(\D{3})(\.)(\d)(\.)(\d{2})(\.)(\d{2})(\.)(\d{2})";
                    HiddenFieldMaskelemeTipi.Value = "6";
                    GenelMetinKutusu.MaxLength = 21;
                    ornekFormat = "B.05.0.İLİ.0.07.00.02";
                    break;
                case MaskelemeTipleri.Eposta:
                    regExpression = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
                    HiddenFieldMaskelemeTipi.Value = "7";
                    uciYazimSekli = YazimSekli.HepsiKucuk;
                    ornekFormat = "a.mehmet@gumruk.gov.tr";
                    break;
                case MaskelemeTipleri.WebAdresi:
                    regExpression = @"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?";
                    HiddenFieldMaskelemeTipi.Value = "8";
                    uciYazimSekli = YazimSekli.HepsiKucuk;
                    ornekFormat = "http://www.gumruk.gov.tr";
                    break;
                case MaskelemeTipleri.Sayi:
                    regExpression = @"(\d+)(\,\d+)?(\ )?";
                    HiddenFieldMaskelemeTipi.Value = "9";
                    ornekFormat = "10 veya 10,05";
                    OzelDogrulamaAyariYap(pMaskelemeTipi);
                    break;
                case MaskelemeTipleri.UlkeTelefonKodu:
                    regExpression = @"(\+)(\()(\d{2})(\d{1})?(\d{1})?(\))";
                    HiddenFieldMaskelemeTipi.Value = "10";
                    GenelMetinKutusu.MaxLength = 7;
                    ornekFormat = "+(90)";
                    break;
                case MaskelemeTipleri.KurumsalKod:
                    regExpression = @"(\d{2})(\.)(\d{2})(\.)(\d{2})(\.)(\d{2})(\.)(\d{2})";
                    HiddenFieldMaskelemeTipi.Value = "11";
                    GenelMetinKutusu.MaxLength = 14;
                    ornekFormat = "44.52.00.62.19";
                    break;
                case MaskelemeTipleri.FonksiyonelKod:
                    regExpression = @"(\d{2})(\.)(\d{1})(\.)(\d{1})(\.)(\d{2})(\.)(\d{3})";
                    HiddenFieldMaskelemeTipi.Value = "12";
                    GenelMetinKutusu.MaxLength = 13;
                    ornekFormat = "01.3.9.01.101";
                    break;
                case MaskelemeTipleri.FinansalKod:
                    regExpression = @"([1-8])";
                    HiddenFieldMaskelemeTipi.Value = "13";
                    GenelMetinKutusu.MaxLength = 1;
                    ornekFormat = "1-8";
                    break;
                case MaskelemeTipleri.ParaKurussuz:
                    HiddenFieldMaskelemeTipi.Value = "14";
                    ornekFormat = "1.520";
                    OzelDogrulamaAyariYap(pMaskelemeTipi);
                    break;
                case MaskelemeTipleri.ButceEkonomikKod:
                    regExpression = @"([0][1-9](\.)[1-9](\.)[1-9](\.)(\d{2}))";
                    HiddenFieldMaskelemeTipi.Value = "15";
                    GenelMetinKutusu.MaxLength = 9;
                    ornekFormat = "01.1.1.01";
                    break;
            }

            if (regExpression != string.Empty)
            {
                if (uciOrnekGoster) LabelOrnek.Text = ornekFormat;
                Dogrulama.MyRegularExpressionValidator(RegularExpressionValidatorGenelMetinKutusu, regExpression, ValidationGroup, "GenelMetinKutusu");
                RegularExpressionValidatorGenelMetinKutusu.ToolTip += " Örnek Format: " + ornekFormat;
                RegularExpressionValidatorGenelMetinKutusu.Visible = true;
            }

        }

        private void OzelDogrulamaAyariYap(MaskelemeTipleri pMaskelemeTipi)
        {
            if (uciMinimumSayi == 0 && uciMaksimumSayi == 0) { RangeValidatorGenelMetinKutusu.Visible = false; return; }

            string minSayi = string.Empty;
            string maxSayi = string.Empty;
            ValidationDataType dogrulamaVeriTipi;

            switch (pMaskelemeTipi)
            {
                case MaskelemeTipleri.OndalikliRakam:
                    minSayi = Convert.ToDouble(uciMinimumSayi).ToString();
                    maxSayi = Convert.ToDouble(uciMaksimumSayi).ToString();
                    dogrulamaVeriTipi = ValidationDataType.Double;
                    break;
                case MaskelemeTipleri.Para:
                    minSayi = Convert.ToDouble(uciMinimumSayi).ToString();
                    maxSayi = Convert.ToDouble(uciMaksimumSayi).ToString();
                    dogrulamaVeriTipi = ValidationDataType.Currency;
                    break;
                case MaskelemeTipleri.SadeceRakam:
                    minSayi = Convert.ToInt32(uciMinimumSayi).ToString();
                    maxSayi = Convert.ToInt32(uciMaksimumSayi).ToString();
                    dogrulamaVeriTipi = ValidationDataType.Integer;
                    break;
                case MaskelemeTipleri.Sayi:
                    minSayi = Convert.ToDouble(uciMinimumSayi).ToString();
                    maxSayi = Convert.ToDouble(uciMaksimumSayi).ToString();
                    dogrulamaVeriTipi = ValidationDataType.Double;
                    break;
                case MaskelemeTipleri.ParaKurussuz:
                    minSayi = Convert.ToDouble(uciMinimumSayi).ToString();
                    maxSayi = Convert.ToDouble(uciMaksimumSayi).ToString();
                    dogrulamaVeriTipi = ValidationDataType.Currency;
                    break;
                default: RangeValidatorGenelMetinKutusu.Visible = false; return;
            }

            Dogrulama.MyRangeValidator(RangeValidatorGenelMetinKutusu, dogrulamaVeriTipi, minSayi, maxSayi, ValidationGroup, "GenelMetinKutusu");
            RangeValidatorGenelMetinKutusu.Visible = true;
        }

        private void YazimSekliniAyarla(YazimSekli pYazimSekli)
        {
            switch (pYazimSekli)
            {
                case YazimSekli.Serbest: HiddenFieldYazimSekli.Value = "0"; break;
                case YazimSekli.HepsiKucuk: HiddenFieldYazimSekli.Value = "1"; break;
                case YazimSekli.HepsiBuyuk: HiddenFieldYazimSekli.Value = "2"; break;
                case YazimSekli.BasharflerBuyuk: HiddenFieldYazimSekli.Value = "3"; break;
            }
        }

        private void KontrolZorunlulukAyari(bool pZorunlumu)
        {
            if (pZorunlumu)
            {
                Dogrulama.MyRequiredFieldValidator(RequiredFieldValidatorGenelMetinKutusu, ValidationGroup, "GenelMetinKutusu");
                RequiredFieldValidatorGenelMetinKutusu.Visible = true;
            }
            else
                RequiredFieldValidatorGenelMetinKutusu.Visible = false;
        }

        private void SetEdilenMetinFormatiniAyarla(string value)
        {
            if (uciMaskelemeTipi == MaskelemeTipleri.Serbest || uciMaskelemeTipi == MaskelemeTipleri.SadeceYazi)
            {
                switch (uciYazimSekli)
                {
                    case YazimSekli.Serbest: GenelMetinKutusu.Text = value; break;
                    case YazimSekli.HepsiKucuk: GenelMetinKutusu.Text = value.ToLower(); break;
                    case YazimSekli.HepsiBuyuk: GenelMetinKutusu.Text = value.ToUpper(); break;
                    case YazimSekli.BasharflerBuyuk: GenelMetinKutusu.Text = ProperCase(value); break;
                }
            }
            else if (uciMaskelemeTipi == MaskelemeTipleri.Para)
            {
                GenelMetinKutusu.Text = ParaMaskeleme(value);
            }
            else if (uciMaskelemeTipi == MaskelemeTipleri.ParaKurussuz)
            {
                string pr = ParaMaskeleme(value);
                GenelMetinKutusu.Text = pr.Split(',').GetValue(0).ToString();
            }
            else
            {
                GenelMetinKutusu.Text = value;
            }
            HiddenFieldText.Value = GenelMetinKutusu.Text;
        }

        private string ProperCase(string pText)
        {
            string txt = pText.ToLower().Trim();

            while (txt.IndexOf("  ") > 0)
            {
                txt = txt.Replace("  ", " ");
            }

            txt = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(txt);
            txt = txt.Replace("Ve ", "ve ");
            txt = txt.Replace("Ab ", "AB ");    

            return txt;
        }

        private string GetEdilenMetinFormatiniAyarla()
        {
            if (uciMaskelemeTipi == MaskelemeTipleri.Para)
            {
                string para = GenelMetinKutusu.Text.Replace(".", "");
                return para;
            }
            if (uciMaskelemeTipi == MaskelemeTipleri.ParaKurussuz)
            {
                return GenelMetinKutusu.Text.Replace(".", "");
            }
            else
            {
                return GenelMetinKutusu.Text;
            }
        }

        private string ParaMaskeleme(string value)
        {
            try
            {
                string para = value.Replace(".", ",");
                string[] parca = para.Split(',');

                string tamKisim = parca[0].ToString();
                string ondalikKisim = "";
                if (parca.Length > 1) ondalikKisim = parca[1].ToString();
                int mod = tamKisim.Length % 3;
                string modKismi = tamKisim.Substring(0, mod);
                string digerKismi = tamKisim.Substring(mod);
                string sonuc = "";

                for (int i = 0; i < digerKismi.Length; i = i + 3)
                {
                    sonuc = sonuc + '.' + digerKismi.Substring(i, 3);
                }
                sonuc = sonuc.Substring(1);
                if (parca.Length > 1) sonuc = modKismi + "." + sonuc + "," + parca[1]; else sonuc = modKismi + "." + sonuc;
                if (sonuc.Substring(0, 1) == ".") sonuc = sonuc.Substring(1);
                return sonuc;
            }
            catch (Exception)
            {
                return value;
            }
        }
    }
}
